﻿using Cl.Utils.Helper;
using Cl.Utils.Primitives.Class;
using Cl.Utils.Primitives.Class.Systems;
using Cl.Utils.Primitives.Class.UploadFile;
using Cl.Utils.Signalr.Hub;
using Elsa.Server.Api.Models;
using Lims.Util.Primitives.Class.Dict;
using Lims.Util.Primitives.Class.Systems;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cl.Utils
{
    /// <summary>
    /// 全局变量
    /// </summary>
    public static class GlobalService
    {

        public static List<ChatInfoData> SignalrConnectedLists = new List<ChatInfoData>();

        public static DefaultDataDto DefaultData = new DefaultDataDto();//CustomerRoleName


        public static RedisServiceConfigDto RedisServiceConfig = new();

        public static int updateDevStateInterval
        {
            get => int.TryParse(ConfigHelper.GetSection("QuartConst:UPDATE_DEV_STATE_INTERVAL"), out int interval) ? interval : 5;
        }
        public static int TimeOutSecond
        {
            get => int.TryParse(ConfigHelper.GetSection("QuartConst:TIME_OUT_SECOND"), out int interval) ? interval : 300;
        }

        public static List<DictModel> SysDictsGlobal = new List<DictModel>();

        /// <summary>
        /// upload上传服务的配置
        /// </summary>
        public static FileConfig FileConfigGlobal = new();

        public static SystemConfig SystemConfigGlobal = new();

        //public static ChaoJiAdminDto ChaoJiAdminConfig = new();


        /// <summary>
        /// 加载初始化全局变量
        /// </summary>
        public static void InitGlobal()
        {
            FileConfigGlobal = ConfigHelper.GetFileConfig();
            //ChaoJiAdminConfig = ConfigHelper.GetChaoJiAdminConfig();
            DefaultData = ConfigHelper.GetDefaultData();
            SystemConfigGlobal = ConfigHelper.GetSystemConfigs();
        }

        /// <summary>
        /// 获取指定总表下的字典-方法吃缓存，需要重启
        /// </summary>
        /// <param name="DICT_KEY">总表KEY</param>
        /// <returns></returns>
        public static List<DictModel> GetDictList(string DICT_KEY)
        {
            return SysDictsGlobal.Where(x => x.DictKey == DICT_KEY).ToList();
        }

        /// <summary>
        /// 获取指定总表下的字段下的key对应的值
        /// </summary>
        /// <param name="DICT_KEY"></param>
        /// <param name="KEY"></param>
        /// <returns></returns>
        public static string GetDictByKey(string DICT_KEY, string KEY)
        {
            var dictList = GetDictList(DICT_KEY);
            var dict = dictList.FirstOrDefault(x => x.Key == KEY);
            if (dict != null)
            {
                return dict.Name;
            }
            return string.Empty;
        }

    }
}
